﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace ClientRegister
{
    public class DataStudentProvider
    {
        ConnectDB connect = new ConnectDB();
        SqlConnection cnn;
        SqlCommand cmd;

        public int insertStudent(string name, int gender, string birthday, string job, int phone, string email, string address)
        {
            cnn = connect.Connect();
            cnn.Open();
            cmd = new SqlCommand("insert into Students(FullName, GenderId, Birthday, Career, Email, Phone, Address, CreateDateTime) "+
                                "values(@name, @gender, @birhday, @job, @email, @phone, @address, @CreateDateTime) select @@IDENTITY", cnn);
            cmd.Parameters.AddWithValue("@name", name);
            cmd.Parameters.AddWithValue("@gender", gender);
            cmd.Parameters.AddWithValue("@birhday", DateTime.Parse(birthday));
            cmd.Parameters.AddWithValue("@job", job);
            cmd.Parameters.AddWithValue("@email", email);
            cmd.Parameters.AddWithValue("@phone", phone);
            cmd.Parameters.AddWithValue("@address", address);
            cmd.Parameters.AddWithValue("@CreateDateTime", DateTime.Now.ToString());
            return int.Parse(cmd.ExecuteScalar().ToString());
        }
    }
}
